package org.example.java.ref;

import com.google.common.collect.Maps;

import java.util.Map;

/**
 * -Xmx20M -XX:+PrintGCDetails
 * Created by juntaozhang on 3/19/15.
 */
public class WidgetTest {
  static final class Widget {
    String a;
    byte[] b;

    public Widget(String a, byte[] b) {
      this.a = a;
      this.b = b;
    }
  }

  public static void main(String[] args) {
    String serialNumber = getSN();//方法内的地址与该位置的地址相同
    Map<String, Widget> map = Maps.newHashMap();
    map.put(serialNumber, new Widget("a", new byte[1024 * 1024]));
    Widget widget = map.get(serialNumber);
    map.remove(serialNumber);
    System.gc();
    System.out.printf("map size is %s.\n", map.size());
    System.out.println(widget);

  }

  private static String getSN() {
    String serialNumber = String.valueOf(System.nanoTime());
    System.out.println(serialNumber);
    return serialNumber;
  }
}
